package com.firegod.group;

import com.alibaba.fastjson.JSONObject;
import com.firegod.commonutils.vo.ResultVo;
import com.firegod.group.service.GroupService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/group")
@Api(tags = "圈子管理")
public class GroupController {

    @Autowired
    private final GroupService groupService;

    @Autowired
    public GroupController(GroupService groupService) {
        this.groupService = groupService;
    }

    @GetMapping("/info/{courseId}")
    public ResultVo getGroupIdByCourseId(@PathVariable String courseId) {
        return ResultVo.ok().data(groupService.getGroupDetail(courseId));
    }

    @PostMapping("/updateGroup")
    public ResultVo updateGroupInfo(@RequestBody JSONObject jsonObject) {
        String courseId = jsonObject.getString("groupId");
        String groupNotice = jsonObject.getString("groupNotice");
        String groupDescription = jsonObject.getString("groupDescription");
        groupService.updateGroup(courseId, groupNotice, groupDescription);
        return ResultVo.ok();
    }
}
